package org.example.config;

import org.example.quartz.job.HotDiscussScoreCompute;
import org.quartz.JobDetail;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
import org.springframework.scheduling.quartz.SimpleTriggerFactoryBean;

@Configuration
public class QuartzConfig {
    //定义一个任务
    @Bean
    public JobDetailFactoryBean computeScoreJob(){
        JobDetailFactoryBean result = new JobDetailFactoryBean();
        result.setJobClass(HotDiscussScoreCompute.class);
        result.setName("computeScoreJob");
        result.setGroup("communityJobGroup");

        result.setDescription("实时计算热贴的分数");
        result.setDurability(true);
        result.setRequestsRecovery(true);
        return result;
    }
    //定义一个触发器  需要一个任务  当我们任务多了 需要区分 用名字
    @Bean
    public SimpleTriggerFactoryBean computeScoreTrigger(JobDetail computeScoreJob){
        SimpleTriggerFactoryBean result = new SimpleTriggerFactoryBean();
        result.setJobDetail(computeScoreJob);
        result.setName("computeScoreTrigger");
        result.setGroup("computeTriggerGroup");
        result.setDescription("实时计算热分数的触发器");
        result.setRepeatInterval(1000 * 60 *2);//2分钟测试一下吧
        return result;

    }
}
